home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Storage / IAStoreStream.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  3.5 KB  |  117 lines  |  [TEXT/CWIE]

  1. // IAStoreStream.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. // for implementing IAStorage on different file systems
  6. // implementations need only implement pure virtual members
  7. // clients should not use this directly, but rather use through an IAStorage
  8.  
  9. #pragma once
  10. #ifndef IAStoreStream_h
  11. #define IAStoreStream_h
  12.  
  13. #pragma import on
  14.  
  15. #if PRAGMA_STRUCT_ALIGN
  16.     #pragma options align=power
  17. #endif
  18.  
  19. #include "IACommon.h"
  20. #include "IAMutex.h"
  21.  
  22. #pragma IA_BEGIN_EXPORTS
  23.  
  24. class IAStoreStream : public IAObject {
  25.     friend class    IAOutputBlock;
  26.     friend class    IAInputBlock;
  27.     friend class    IAStorage;
  28. public:
  29.                     IAStoreStream();
  30.     virtual            ~IAStoreStream();
  31.     // Returns a new storeStream read/writing the same store
  32.     virtual IAStoreStream*    Clone() = 0;
  33.  
  34.     virtual bool    IsOpen() = 0;
  35.     virtual bool    IsWritable() = 0;
  36.     
  37.      IAMutex*            GetMutex() const {return mutex;}
  38. protected:
  39.     // ** Implementations of the following should lock the mutex while executing **
  40.  
  41.     // creates a new store
  42.     virtual void    Initialize() = 0;
  43.     // opens an existing store, enabling changes when 'writable' is true
  44.     virtual void    Open(bool writeable) = 0;
  45.  
  46.     // flushes buffered output to disk
  47.     virtual void    Flush() = 0;
  48.  
  49.     // returns one greater than the last position currently occupied
  50.     virtual uint32    GetEOF() = 0;
  51.     // truncates or extends the storage to the requested length
  52.     virtual void    SetEOF(uint32 address) = 0;
  53.  
  54.     // ** Remaining are only called with the mutex already locked. **
  55.  
  56.     virtual void    Write(uint32 address, const byte* data, uint32 length) = 0;
  57.     virtual uint32    Read(uint32 address, byte* data,  uint32 length) = 0;
  58.     
  59.     // Should be called by Flush() implementations.
  60.     void            MaybeFlushBuffer();    // write buffer if it's dirty & mark it clean
  61. private:
  62.     /// ** The following are only used by our friends, IAOutputBlock, IAInputBlock & IAStorage.
  63.  
  64.     // returns the position where the next read or write will happen
  65.     uint32            GetPosition() { return bufferPos + (nextByte - buffer); }
  66.     // sets the position where the next read or write will happen
  67.     // when writable, this will silently extend the file past EOF
  68.     // blockSize sets the limit for reading or writing
  69.     void            SetPosition(uint32 address, uint32 blockSize);
  70.  
  71.     // i/o primitives
  72.     // each increments the position by the number of bytes read or written
  73.     // reads may not be alternated with writes without an intervening call reposition
  74.     void            WriteByte(byte b) {
  75.                         if (nextByte < endByte) {
  76.                           *(nextByte++) = b;
  77.                         } else WritePastEndOfBuffer(b);
  78.                     }
  79.     byte            ReadByte() {
  80.                         return nextByte < endByte ? *(nextByte++) : ReadPastEndOfBuffer();
  81.                     }
  82.     void            WriteUInt32(uint32 i);
  83.     uint32            ReadUInt32();
  84.     void            WriteBytes(const void* b, uint32 l);
  85.     void            ReadBytes(void* b,  uint32 l);
  86.  
  87.     // really private stuff
  88.     byte*            buffer;                // the buffer
  89.     byte*            nextByte;            // pointer to the next character to read in buffer
  90.     byte*            endByte;            // pointer to the end of the buffer
  91.     uint32            bufferSize;            // amount to read/write     
  92.     uint32            bufferPos;            // position of the first char in buffer
  93.     uint32            blockEnd;            // don't permit read/writes past this     
  94.     bool            bufferDirty;
  95.  
  96.     byte            ReadPastEndOfBuffer();
  97.     void            WritePastEndOfBuffer(byte b);
  98.     IAMutex*        mutex;
  99.  
  100.                     IAStoreStream(IAStoreStream&);        // don't define a copy constructor
  101. };
  102.  
  103. IAExceptionCode            StoreError = 'VSEr';
  104. IAExceptionCode            StoreFull = 'VSFu';
  105. IAExceptionCode            StorePastBlockEnd = 'VSPB';
  106. IAExceptionCode            StorePastEOF = 'VSEo';
  107.  
  108. #pragma IA_END_EXPORTS
  109.  
  110. #if PRAGMA_STRUCT_ALIGN
  111.     #pragma options align=reset
  112. #endif
  113.  
  114. #pragma import reset
  115.  
  116. #endif
  117.